#!/bin/bash

if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi

sql="
use yk_jtp_app_dim;
drop function if exists aaa;
add jar hdfs://node101:8020/warehouse/app_jars/jtp-log-warehouse-1.0-SNAPSHOT.jar;
create temporary function aaa as 'com.gh';

with area as (
    select * from jtp_app_ods.ods_md_areas where dt = '${data_date}'
)
insert overwrite table jtp_app_dim.dim_md_areas partition (dt = '${data_date}')
select
    t4.id,
    t1.areaname,
    t2.areaname,
    t3.areaname,
    t4.areaname,
    t4.bd09_lng,
    t4.bd09_lat,
    aaa(t4.bd09_lat,t4.bd09_lng,6)
from area t1
left join area t2 on t1.id = t2.parentid
left join area t3 on t2.id = t3.parentid
left join area t4 on t3.id = t4.parentid
where t1.parentid = 0
and t4.bd09_lat is not null
and t4.bd09_lng is not null;
"
/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${sql}"